package com.fht.service.statement.impl;

import com.fht.entity.StatementManage;
import com.fht.from.StatementFrom;
import com.fht.mapper.statement.StatementManageMapper;
import com.fht.service.statement.StatementManageService;
import com.fht.util.UnitConversionUtil;
import com.fht.vo.LayUITableVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class StatementManageServiceImpl implements StatementManageService {


    @Resource
    public StatementManageMapper statementManageMapper;

    @Override
    public LayUITableVO<List<StatementManage>> findPage(Map<String, Object> map) {
        StatementFrom from = (StatementFrom) map.get("from");

        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));

        Example example = new Example(StatementManage.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("merchantsId",from.getMerchantsId());


        List<StatementManage> list = statementManageMapper.selectByExample(example);
        for (StatementManage statementManage : list) {
            statementManage.setSaleTotalString(UnitConversionUtil.conversion(statementManage.getSaleTotal()));
            statementManage.setChargebackTotalString(UnitConversionUtil.conversion(statementManage.getChargebackTotal()));
            statementManage.setIncomeTotalString(UnitConversionUtil.conversion(statementManage.getIncomeTotal()));
            statementManage.setCashString(UnitConversionUtil.conversion(statementManage.getCash()));
            statementManage.setWeChatString(UnitConversionUtil.conversion(statementManage.getWeChat()));
            statementManage.setAlipayString(UnitConversionUtil.conversion(statementManage.getAlipay()));
            statementManage.setBankCardString(UnitConversionUtil.conversion(statementManage.getBankCard()));
            statementManage.setMeituanString(UnitConversionUtil.conversion(statementManage.getMeituan()));
            statementManage.setElemeString(UnitConversionUtil.conversion(statementManage.getEleme()));

        }

        PageInfo<StatementManage> pageInfo = new PageInfo<>(list);

        LayUITableVO<List<StatementManage>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;
    }
}
